package com.fuyu.system.models.vo.menu;


import com.fuyu.system.entity.SysMenu;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class SysMenuRouterVO {
    @Schema(description = "菜单id")
    private Long menuId;

    @Schema(description = "父菜单id")
    private Long parentId;

    @Schema(description = "请求地址")
    private String path;

    @Schema(description = "组件地址")
    private String component;

    @Schema(description = "重定向")
    private String redirect;

    private SysMenuRouterMeta meta;

    private List<SysMenuRouterVO> children = new ArrayList<SysMenuRouterVO>();


    public static SysMenuRouterVO toVO(SysMenu sysMenu) {

        SysMenuRouterVO sysMenuRouterVO = new SysMenuRouterVO();

        sysMenuRouterVO.setMenuId(sysMenu.getMenuId());
        sysMenuRouterVO.setParentId(sysMenu.getParentId());
        sysMenuRouterVO.setPath(sysMenu.getPath());
        sysMenuRouterVO.setComponent(sysMenu.getComponent());
        sysMenuRouterVO.setRedirect(sysMenu.getRedirect());
        sysMenuRouterVO.setMeta(
                SysMenuRouterMeta.builder()
                        .title(sysMenu.getTitle())
                        .icon(sysMenu.getIcon())
                        .visible(sysMenu.getVisible())
                        .build()
        );

        return sysMenuRouterVO;
    }
}
